fix: plugin produces no output due to bindMethod failing on class instances (on opencode 1.4.7)#1
Open
raphaelfavier wants to merge 1 commit into
Conversation
OpenCode's plugin context exposes client APIs as class instances, whose methods are not enumerable own properties. bindMethod() walks own properties and returns null for such methods, causing fetchSessionSnapshot to throw 'Session API unavailable' and logEvent to silently skip logging. Replace all three bindMethod call sites with direct typed casts: - fetchSessionSnapshot: cast ctx.client to a typed interface and call session.get / .messages / .todo / .diff directly - logEvent: cast ctx.client.app and call .log() inside a try/catch, falling back to console.error on failure - debug init block: typeof checks on the typed cast instead of bindMethod Diagnosed and confirmed via a live debugging session where the plugin produced no output despite initialising correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The plugin initialises correctly but never writes any files. The root cause is that
fetchSessionSnapshotusesbindMethod()to extractget,messages,todo, anddifffromctx.client.session. Because the OpenCode client exposes these as class instance methods (on the prototype, not as own enumerable properties),bindMethod()returnsnullfor all of them. The null-check guard then throws:Session API unavailable on plugin context
This error is swallowed silently because
logEventhas the same bug. It also usesbindMethodto findclient.app.log, gets null back, and falls through without logging anything.Diagnosed via a live debugging session (OpenCode 1.4.7).
Fix
Replace all
bindMethodcall sites that access client APIs with direct typed casts (ctx.client as { session: { get: ..., ... } }), calling methods directly. Atry/catchfallback is used inlogEventto preserve the console fallback behaviour.Three sites changed:
fetchSessionSnapshot— direct typed cast + call methods on the castlogEvent— direct typed cast inside try/catch, fall through to console on failuretypeofchecks on the typed cast instead ofbindMethodNo behaviour changes beyond fixing the broken API calls.